<script>
import BasicInfo from '@/views/dispatch/transport/components/transportDetail/components/basicInfo.vue'
import { mapState } from 'vuex'
import MapInfo from '@/views/dispatch/transport/components/transportDetail/components/mapInfo.vue'

export default {
  name: 'transportDetail',
  data() {
    return {
      loading: false
    }
  },
  components: { MapInfo, BasicInfo },
  methods: {
    /*
    *
    * 统一获取
    *  */
    async fetchAllInfo() {
      try {
        this.loading = true
        await Promise.all([this.$store.dispatch('transportStore/fetchTransportDetailAction', this.id), this.$store.dispatch('transportStore/fetchTransportMapAction', this.id)])
      } catch (error) {
        this.$message.error(error.message)
      } finally {
        this.loading = false
      }
    }
    /*
    *
    * 获取运单任务详情的回调函数
    *
    async fetchTransportDetail() {
      try {
        await this.$store.dispatch('transportStore/fetchTransportDetailAction', this.id)
      } catch (error) {
        this.$message.error(error.message)
      }
    },
    *  */

    /*
    *
    * 获取运输任务坐标的回调函数
    *
    async fetchTransportMap() {
      try {
        await this.$store.dispatch('transportStore/fetchTransportMapAction', this.id)
      } catch (error) {
        this.$message.error(error.message)
      }
    }
    * */
  },
  mounted() {
    // this.fetchTransportDetail()
    // this.fetchTransportMap()
    this.fetchAllInfo()
  },
  computed: {
    id() {
      return this.$route.query.id
    },
    ...mapState('transportStore', ['transportDetail'])
  }
}
</script>

<template>
  <div class="transportDetail" v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" element-loading-background="rgba(255,255,255)">
    <basic-info :detail="transportDetail" v-if="transportDetail"></basic-info>
    <map-info :detail="transportDetail" v-if="transportDetail"></map-info>
    <el-card shadow="never" class="cargo-info">
      <div slot="header" class="clearfix">
        <span>货品信息</span>
      </div>
      <el-table :data="transportDetail.transportOrders" style="width: 100%" stripe :header-cell-style="{ background: 'rgba(250,252,255,1)' }">
        <el-table-column label="序号" type="index" align="center" width="60"/>
        <el-table-column label="运单编号" prop="id" align="center"></el-table-column>
        <el-table-column label="下单时间" prop="created" align="center"></el-table-column>
        <el-table-column label="发件人姓名" align="center">
          <template #default="{row}">{{ row.order.receiverName }}</template>
        </el-table-column>
        <el-table-column label="发件人电话" align="center">
          <template #default="{row}">{{ row.order.senderPhone }}</template>
        </el-table-column>
        <el-table-column label="发件人地址" align="center">
          <template #default="{row}">{{ row.order.senderAddress + '-' + row.order.receiverAddress }}</template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="{row}">
            <el-button type="text" @click="$router.push({ path:'/waybill-detail', query:{ id:row.id,orderId:row.orderId}})">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-card shadow="never" class="delivery-info">
      <div slot="header" class="clearfix">
        <span>交付照片</span>
      </div>
      <div class="body">
        <img :src="transportDetail.deliverPicture" alt="货品照片" title="货品照片">
        <img :src="transportDetail.transportCertificate" alt="凭证照片" title="凭证照片">
      </div>
    </el-card>
    <el-card shadow="never" class="pick-info">
      <div slot="header" class="clearfix">
        <span>提货照片</span>
      </div>
      <div class="body">
        <img :src="transportDetail.cargoPicture" alt="货品照片" title="货品照片">
        <img :src="transportDetail.cargoPickUpPicture" alt="凭证照片" title="凭证照片">
      </div>
    </el-card>
  </div>
</template>

<style scoped lang="scss">
.transportDetail {
  margin: 20px;

  .cargo-info {
    margin-top: 10px;
  }

  .delivery-info {
    margin: 10px 0;
  }

  .body {
    display: flex;
    justify-content: space-around;

    img {
      width: 200px;
      cursor: pointer;
    }
  }
}
</style>
